/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: AliceMana
 * Date: 2022-12-28
 * Time: 12:47
 */
public class Solution {
    // https://leetcode.cn/problems/remove-duplicates-from-sorted-array/
    public int removeDuplicates(int[] nums) {
        int j = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != nums[j]) {
                nums[++j] = nums[i];
            }
        }
        return j+1;
    }



    // https://leetcode.cn/problems/truncate-sentence/
    public static String truncateSentence(String s, int k) {
        String[] strings = s.split(" ");
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < k; i++) {
            stringBuilder.append(strings[i]);
            if (i < k-1) {
                stringBuilder.append(" ");
            }
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        String s = "What is the solution to this problem";
        System.out.println(truncateSentence(s, 4));
    }
}
